function userMessageS(){
    return new Promise((reslove,reject)=>{
        axios({
            url:'/picture/session',
        }).then((data)=>{
            reslove(data)
        }).catch((err)=>{
            reject(err)
        })
    })
}

userMessageS().then(data=>{
    let sessionUserid=undefined
    if(data.data.session){
        sessionUserid=data.data.session.id
    }
})



// 封装选择器函数
function $(selector){
    var c=selector.substring(0,1);//获取第一个字符
    if(c=="#"){
        return document.getElementById(selector.substring(1,selector.length));//返回相应的元素
    }else if(c == '.'){
        return document.getElementsByClassName(selector.substring(1,selector.length))
    }else{
        return document.getElementsByTagName(selector);
    }
}
// let userId=getCookie('userId')
// console.log(userId);
// var userId = 6//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//让图片居中显示
function imgOnload(e) {
	var wid = e.parentNode.offsetWidth;//父容器限制高度
	var hei = e.parentNode.offsetHeight;//父容器限制宽度
	var realWidth = e.width; //储存图片实际宽度
	var realHeight = e.height; //储存图片实际高度
	//获取图片宽高比
	var realwh = e.width / e.height;
	if(realwh > wid/hei) {
		var w = ((hei / realHeight) * realWidth) + 'px';
		var h = hei + 'px';
		var l = '-' + ((hei / realHeight) * realWidth - wid) / 2 + 'px';
		e.style.width = w; //等比缩放宽度
		e.style.height = h; //跟div高度一致
		e.style.left = l; //设置图片相对自己位置偏移为img标签的宽度-高度的一半
		e.style.position = 'relative';
	} else {
		var w = wid +'px';
		var h = ((wid / realWidth) * realHeight) + 'px';
		var t = '-' + ((wid / realWidth) * realHeight - hei) / 2 + 'px';
		e.style.width = w; //等比缩放宽度
		e.style.height = h; //跟div高度一致
		e.style.top = t; //设置图片相对自己位置偏移为img标签的宽度-高度的一半
		e.style.position = 'relative';
	}
}





function throttle(func,delay){
    let timer
    return ()=>{
        let context = this
        if(timer) return
        timer = setTimeout(()=>{
            func.apply(context)
            timer = null
        },delay)
    }
}
//监听滚动条，返回页面顶部
let scrollTime = null
window.addEventListener('scroll',scrollFunc)
function scrollFunc(){
    clearTimeout(scrollTime)
    scrollTime = setTimeout(function(){
        var scrollTop = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop;
        if(scrollTop > 1298){
            $('.toTop')[0].style.display = 'inline-block'
        }else{
            $('.toTop')[0].style.display = 'none'
        }
    },600)

}





//轮播图


let keys=0;
let imgVessel = document.querySelectorAll('.imgVessel')
let pointVessel = document.querySelector('.pointVessel')
let point = document.querySelectorAll('.point')
let sFContainer=document.querySelector('.sFContainer')

//创建轮播图的函数
let Carousel = (i)=>{
    imgVessel[i].style.opacity="1"
    point[i].style.border="none"
    point[i].style.backgroundColor="#d6555f"
    setTimeout(function(){
        imgVessel[i].style.zIndex="1"
    },1000)
    for(let j=0;j<imgVessel.length;j++){
        if(i==j){
            continue;
        }
        imgVessel[j].style.opacity="0"
        point[j].style.backgroundColor="transparent"
        point[j].style.border="solid 3px white"
        setTimeout(function(){
            imgVessel[j].style.zIndex="0"
        },1000)
    }
}
//初始
Carousel(keys)
//定时器轮播
//定时器让轮播图轮播
var timer
let TimeCarousel=()=>{
    timer=setInterval(() => {
        keys++
        if(keys>=imgVessel.length){
            keys=0;
        }
        Carousel(keys)
    }, 3000);
}
TimeCarousel(keys)
//点击轮播图下面的小圆点，可以切换对应的图片
for(let i=0;i<point.length;i++){
    point[i].addEventListener('click',function(){
        keys=i
        Carousel(keys)
        clearInterval(timer)
        TimeCarousel(keys)
    })
}
//左右切换
let imgLeft=document.querySelector('.imgLeft')
let imgRight=document.querySelector('.imgRight')
imgLeft.addEventListener('click',function(){
    keys--
    if(keys<0){
        keys=2
    }
    Carousel(keys)
    clearInterval(timer)
    TimeCarousel(keys)
})
imgRight.addEventListener('click',function(){
    keys++
    if(keys>=imgVessel.length){
        keys=0
    }
    Carousel(keys)
    clearInterval(timer)
    TimeCarousel(keys)
})

//每日精选和关注动态
let navContent=document.querySelectorAll('.navContent')
let navC=document.querySelectorAll('.navC')
let dailyDunamic=document.querySelectorAll('.dailyDunamic')
//点击函数切换背景颜色字体颜色函数
let cut=(i)=>{
    for(let j=0;j<navContent.length;j++){
        if(i==j){
            navContent[i].style.backgroundColor='rgba(214, 85, 95, .3)'
            navC[i].style.color='#d6555f'
            dailyDunamic[i].style.display="block"
            continue;
        }
            navContent[j].style.backgroundColor='white'
            navC[j].style.color='#000000'
            dailyDunamic[j].style.display="none"
    }
}







//获得喜欢收藏状态
async function getLikeLove(postId,userId){
    let obj = {}
    let color = null
    let loveColor = null
    let loveStage = null
    let liekStageAns = await axios.get(`/index/likeStatus?postId=${postId}&userId=${userId}`)
    likeStage = liekStageAns.data.data.data
    if(likeStage == 0){//0是没有点赞
        color = '#777777'//点赞的颜色
    }else{
        color = '#D6222E'
    }
    obj['color'] = color
    let loveStageAns = await axios.get(`/index/lovePost?postId=${postId}&userId=${userId}`)
    loveStage = loveStageAns.data.data.data
    if(loveStage == 0){//0是没有点赞
        loveColor = '#777777'
    }else{
        loveColor = '#D6222E'
    }
    obj['loveColor'] = loveColor
    return obj
}
let changeLookNum = (number)=>{
    if(number > 1000){
        let sss = String(lookNum)
        lookNum = `${sss.slice(0,sss.length-3)}.${sss.slice(sss.length-3,sss.length-2)}万`
    }
    return number
}


async function getLikeLoveS(postId){
    let obj = {}
    obj['color'] = '#777777'
    obj['loveColor'] = '#777777'
    return obj
}

let postId = null
//获取关注人的帖子
function getFollowPostFunc(userId,pageSize,pageNum){
    userMessageS().then(data=>{
        let sessionUserid=undefined
        if(data.data.session){
            sessionUserid=data.data.session.id
        }
        let str = dailyDunamic[1].innerHTML
    let loading=document.querySelector('.loading')
    if(sessionUserid==undefined){
        str = `
            <div>请先登录</div>
        `
        dailyDunamic[1].innerHTML = str
    }else{
        axios.get(`/index/follow?userId=${userId}&pageNum=${pageNum}&pageSize=${pageSize}`)
        .then(data=>{
            let aa = data.data.key.data
            let followAllPage = aa.pageCount
            if(typeof aa === 'string'){
                $('.loading')[0].innerHTML = `
                ${aa}
                `
            }else{
                let res = aa.forums
                // let str = dailyDunamic[1].innerHTML
                let time = new Date()
                let promiseList = []
                for(let i = 0;i < res.length;i++){
                    postId = res[i].id
                    //这是每一个帖子
                    promiseList.push(getLikeLove(postId,sessionUserid))
            
                }
                Promise.all(promiseList).then((obj)=>{
                    for(let i = 0;i < obj.length;i++){
                        let manyNum = obj[i]
                        let imgSrc = getPicLength(res[i].path)
                        // let imgLayout = picLayout(imgSrc.length,i)
                        str += `
                        <div class="content follow" data-postid="${res[i].id}">
                            <div class="acontent aFollow">
                                <div class="contentHead followHead">
                                    <img class="contentHeadImg followHeadImg" src="${res[i].portrait}" onclick="toPersonal(${res[i].userId})"/>
                                    <div class="contentheadRight headRight">
                                        <p class="contentName followName">${res[i].name}</p>
                                        <p class="contentTime followTime">${timeDiffer(res[i].time,time)}</p>
                                    </div>
                                    <div class="contentheadLook lookNumDiv">
                                        <p class="contentLookNum loonNum">${changeLookNum(res[i].visit)}</p>
                                        <p>浏览</p>
                                    </div>
                                </div>
                                <p class="contentcContent followcontent">${res[i].context}</p>
                                <div class="contentImg followImg" data-id="${res[i].id}" onclick="getDetail(this)">
                                    <ul>
                                        ${
                                            picLayout(imgSrc) 
                                        }
                                        

                                    </ul>
                                    
                                </div>
                                <div class="contentBottom followBottom">
                                    <div style="color:${manyNum.color}" class="contentLike followLike" data-id="${res[i].id}" onclick="likeFunc(this)">
                                        <i class="iconfont icon-dianzan"></i><p class="likeNum">${res[i].thumbUpCount}</p>
                                    </div>
                                    <div style="color:${manyNum.loveColor}" class="contentLove followLove" data-id="${res[i].id}" onclick="loveFunc(this)">
                                        <i class="iconfont icon-shoucang"></i><p class="loveNum">${res[i].collectCount}</p>
                                    </div>
                                    <div class="contentReport report" onclick="reportFunc(this)" data-id="${res[i].id}" data-reportedId="${res[i].userId}" data-reportedUserName='${res[i].name}'>
                                        <i class="iconfont icon-icon_jubao-xian"></i>举报
                                    </div>
                                </div>
                            </div>
                        </div>
                        `

                    }
                    dailyDunamic[1].innerHTML = str


                    //懒加载
                    let observeFollow = new IntersectionObserver(function(event){
                        if(event[0].intersectionRatio > 0){
                            observeFollow.unobserve($('.dailyDunamic')[1].lastElementChild)
                            if(followPage >= followAllPage){
                                $('.loading')[0].innerHTML = '没有内容了，看点别的去吧'
                            }else{
                                $('.loading')[0].innerHTML = `
                                <img src="../public/img/5-121204193R0-50.gif"/>
                                <p>努力加载中...</p>
                                `
                                followPage += 1
                                getFollowPostFunc(sessionUserid,5,followPage)      
                            }
                        }
                    })
                    observeFollow.observe($('.dailyDunamic')[1].lastElementChild)
                })
                promiseList = []
                console.log(`followPage${followPage}`)
            }
        })
    }
    })
}
let followPage = 1

// userMessageS().then(data=>{
//     let sessionUserid=undefined
//     if(data.data.session){
//         sessionUserid=data.data.session.id
//     }
//     getFollowPostFunc(sessionUserid,5,followPage)
// })

let creamAllPage = null 
//每日精选
function getCreamPostFunc(pageNum){
    axios.get(`/index/daily?pageNum=${pageNum}`)
    .then(data=>{
        userMessageS().then(value=>{
            let sessionUserid=undefined
            if(value.data.session){
                sessionUserid=value.data.session.id
            }
            creamAllPage = data.data.data.data.pageCount
            let aa = data.data.data.data
            // console.log(aa.list)
            let res = aa.forums
                let str = dailyDunamic[0].innerHTML
                let time = new Date()
                let promiseList = []
                for(let i = 0;i < res.length;i++){
                    postId = res[i].id
                    //这是每一个帖子
                    if(sessionUserid==undefined){
                        promiseList.push(getLikeLoveS(postId))
                    }else{
                        promiseList.push(getLikeLove(postId,sessionUserid))
                    }
                }
                Promise.all(promiseList).then((obj)=>{
                    for(let i = 0;i < obj.length;i++){
                        // console.log(res[i].time)
                        let manyNum = obj[i]
                        let imgSrc = getPicLength(res[i].path)
                        // let imgLayout = picLayout(imgSrc.length,i)
                        str += `
                        <div class="content follow" data-postid="${res[i].id}">
                            <div class="acontent aFollow">
                                <div class="contentHead followHead">
                                    <img class="contentHeadImg followHeadImg" src="${res[i].portrait}" onclick="toPersonal(${res[i].userId})"/>
                                    <div class="contentheadRight headRight">
                                        <p class="contentName followName">${res[i].name}</p>
                                        <p class="contentTime followTime">${timeDiffer(res[i].time,time)}</p>
                                    </div>
                                    <div class="contentheadLook lookNumDiv">
                                        <p class="contentLookNum loonNum">${changeLookNum(res[i].visit)}</p>
                                        <p>浏览</p>
                                    </div>
                                </div>
                                <p class="contentcContent followcontent">${res[i].context}</p>
                                <div class="contentImg followImg" data-id="${res[i].id}" onclick="getDetail(this)">
                                    <ul>
                                        ${
                                            picLayout(imgSrc) 
                                        }
                                    </ul>
                                </div>
                                <div class="contentBottom followBottom">
                                    <div style="color:${manyNum.color}" class="contentLike followLike" data-id="${res[i].id}" onclick="likeFunc(this)">
                                        <i class="iconfont icon-dianzan"></i><p class="likeNum">${res[i].thumbUpCount}</p>
                                    </div>
                                    <div style="color:${manyNum.loveColor}" class="contentLove followLove" data-id="${res[i].id}" onclick="loveFunc(this)">
                                        <i class="iconfont icon-shoucang"></i><p class="loveNum">${res[i].collectCount}</p>
                                    </div>
                                    <div class="contentReport report" onclick="reportFunc(this)" data-id="${res[i].id}" data-reportedId="${res[i].userId}" data-reportedUserName='${res[i].name}'>
                                        <i class="iconfont icon-icon_jubao-xian"></i>举报
                                    </div>
                                </div>
                            </div>
                        </div>
                        `

                    }
                    dailyDunamic[0].innerHTML = str
                    //懒加载
                    let observeCream = new IntersectionObserver(function(event){
                        if(event[0].intersectionRatio > 0){
                            observeCream.unobserve($('.dailyDunamic')[0].lastElementChild)
                            if(creamPage >= creamAllPage){
                                $('.loading')[0].innerHTML = '没有内容了，看点别的去吧'
                            }else{
                                $('.loading')[0].innerHTML = `
                                <img src="../public/img/5-121204193R0-50.gif"/>
                                <p>努力加载中...</p>
                                `
                                creamPage += 1
                                getCreamPostFunc(creamPage)      
                            }
                        }
                    })
                    observeCream.observe($('.dailyDunamic')[0].lastElementChild)
                })
                promiseList = []
                console.log(`creamPage${creamPage}`)
            })
    })
}
let creamPage = 1   
getCreamPostFunc(creamPage)


let onceGetFollow = true
//每日精选和关注动态点击切换颜色
userMessageS().then(data=>{
    let sessionUserid=undefined
    if(data.data.session){
        sessionUserid=data.data.session.id
    }
    for(let i=0,len=navContent.length;i<len;i++){
        navContent[i].addEventListener('click',function(){
            let loading=document.querySelector('.loading')
            //没有登陆而且去看关注了
            if(sessionUserid==undefined&&i==1){
                // loading.style.display='none'
                $('.loading')[0].innerHTML = `
                <p>请先登录</p>
                `
            }else{
                if(i == 1){
                    if(onceGetFollow){
                        onceGetFollow = false
                        //登录了去看关注了而且是第一次看关注
                        getFollowPostFunc(sessionUserid,5,followPage)
                    }else{

                    }
                }else{
                    //登录了去看每日精华了
                    // loading.style.display='inline-flex'
                    if(creamPage >= creamAllPage){
                        $('.loading')[0].innerHTML = '没有内容了，看点别的去吧'
                    }else{
                        $('.loading')[0].innerHTML = `
                        <img src="../public/img/5-121204193R0-50.gif"/>
                        <p>努力加载中...</p>
                        `     
                    }
                }
            }
            cut(i)
        })
    }
})

//点击头像要去个人主页
function toPersonal(userId){
    window.location.href = `/picture/picture?userId=${userId}`
}


//获得帖子照片的数组
function getPicLength(path){
    if(path == null){
        return ' '
    }else{
        let imgSrc = path.split('::')
        return imgSrc

    }
}

//照片数组，改变布局
function picLayout(picArr){
    let str = ''
    for(let i = 0;i < picArr.length;i++){
        // str += `
        // <li><img onload=imgOnload(this) src="${picArr[i]}"/></li>
        // `
        str += `
        <li><img style="width:100%;height:100%;object-fit: cover;object-position: center center;" src="${picArr[i]}"/></li>
        `
    }
    return str
}


//点赞或者取消点赞
function likeFunc(a){
    userMessageS().then(data=>{
        // console.log(data);
        let sessionUserid=undefined
        if(data.data.session){
            sessionUserid=data.data.session.id
        }
        // console.log(sessionUserid);
        if(sessionUserid!=undefined){
            let postId = Number(a.getAttribute('data-id'))
            axios({
                method:"post",
                url:'/index/like',
                data:{
                    userId:sessionUserid,
                    postId:postId
                }
                
            }).then((data)=>{
                let res = data.data.data.data
                let inner = Number(a.children[1].innerHTML)
                if(res == 1){//点赞
                    inner += 1
                    a.style.color = '#D6222E'
                }else{//取消
                    a.style.color = '#777777'
                    inner -= 1
                }
                a.children[1].innerHTML = inner
            }).catch((err)=>{
                console.log(err)
            })
        }else{
            // location.href=`/login`
            toLoginTipFunc()
        }
    })
}
//收藏或者取消收藏
function loveFunc(a){
    userMessageS().then(data=>{
        let sessionUserid=undefined
        if(data.data.session){
            sessionUserid=data.data.session.id
        }
        if(sessionUserid!=undefined){
            let postId = Number(a.getAttribute('data-id'))
            axios({
                method:"post",
                url:'/index/love',
                data:{
                    userId:sessionUserid,
                    postId:postId
                }
                
            }).then((data)=>{
                let res = data.data.data.data
                let inner = Number(a.children[1].innerHTML)
                if(res == 1){//点赞
                    inner += 1
                    a.style.color = '#D6222E'
                }else{//取消
                    a.style.color = '#777777'
                    inner -= 1
                }
                a.children[1].innerHTML = inner
            }).catch((err)=>{
                console.log(err)
            })
        }else{
            // location.href=`/login`
            toLoginTipFunc()
        }
    })
}

//点图片会跳转到图片详情
function getDetail(a){
    window.location.href = `/picture/picDetail?postId=${a.getAttribute('data-id')}`
}



//点举报！！
var reportBox = $('.reportBox')[0]


    

function reportFunc(a){
    userMessageS().then(data=>{
        userMessageS().then(data=>{
            let sessionUserid=undefined
            if(data.data.session){
                sessionUserid=data.data.session.id
            }
            if(sessionUserid!=undefined){
                reportcontentId = Number(a.getAttribute('data-id'))
                reportedUser = Number(a.getAttribute('data-reportedId'))
                reportedUserName = a.getAttribute('data-reportedUserName')
                reportBox.style.display = 'block'
            }else{
                // location.href=`/login`
                toLoginTipFunc()
            }
        })
    })
}
userMessageS().then(data=>{
    let sessionUserid=undefined
    if(data.data.session){
        sessionUserid=data.data.session.id
    }
    let reportReason = null
    reportType = 0
    reportUser = sessionUserid
    reportUserName = null
    reportcontentId = null
    reportedUser = null
    reportedUserName = null
//确认举报
$('.reportBtn')[0].onclick = function(){
    reportReason = $('.reportInput')[0].value
    if(reportReason.length != 0){
        $('.reportEmpty')[0].style.display = 'none'
        axios({
            method:'post',
            data:{
                reportReason:reportReason,
                reportType:reportType,
                reportUser:reportUser,
                reportUserName:$('.userName')[0].innerHTML,
                reportcontentId:reportcontentId,
                reportedUser:reportedUser
            },
            url:"/index/report"
        }).then(data=>{
            //举报成功之后
            reportBox.style.display = 'none'
            reportInput.value = ''
            tigs('举报成功，我们将根据您的举报做出相应处理！',true)
            console.log(data)
        }).catch(err=>{
            console.log(err)
        })
    }else{
        $('.reportEmpty')[0].style.display = 'inline-block'
    }

}
})


//选择举报原因
var reportList = $('.reportList')
    reportInput = $('.reportInput')[0]
    reportUl = $('.reportUl')[0]

reportInput.onclick = ()=>{
    if(reportUl.style.display === 'block'){
        reportUl.style.display = 'none'

    }else{
        reportUl.style.display = 'block'
    }
}
for(let i = 0;i < reportList.length;i++){
    reportList[i].onclick = ()=>{
        reportInput.value = reportList[i].innerHTML
        reportUl.style.display = 'none'
    }
}
//关闭举报
var closeReport = $('.closeReport')[0]
closeReport.onclick = ()=>{
    reportBox.style.display = 'none'

}


//判断时间差的方法
function timeDiffer(pre,now){
    let preTime = pre.split('-')
        preYear = preTime[0]//发布帖子的年份
        preMonth = preTime[1]//发布帖子的月份
        preMore = preTime[2].split(':')//发布帖子的日 时分秒
        preDayHour = preMore[0].split(' ')//发布帖子的日 时
        preDay = preDayHour[0]//发布帖子的日
        preHour = preDayHour[1]//发布帖子的时
        premin = preMore[1]//发布帖子的分
        preSecond = preMore[2]//发布帖子的秒


        nowYear = now.getFullYear()//当前日期的年
        nowMonth = now.getMonth()//月
        nowDay = now.getDate()//日
        nowHour = now.getHours()
        nowMin = now.getMinutes()
        nowSecond = now.getSeconds()

        day = null

    if(preDay == nowDay){
        day = '今天'
    }else if((preDay==31 && nowDay==1)||(preDay==30 && nowDay==1)||(preDay==29 && nowDay==1)||(preDay==28 && nowDay==1)){
        day = '昨天'
    }else if(nowDay - preDay == 1){
        day = '昨天'
    }else{
        day = `${preMonth}月${preDay}日`
    }
    return `${day} ${preHour}:${premin}`
}


function getRecommend(){
    userMessageS().then(data=>{
        let sessionUserid=undefined
        if(data.data.session){
            sessionUserid=data.data.session.id
        }
    
    if(sessionUserid){
        axios({
            method:"get",
            url:`/index/recommend?userId=${sessionUserid}`
        }).then(data=>{
            let ans = data.data.data.data
            let str = ''
            $('.reContent')[0].innerHTML = ''
            for(let i = 0;i < ans.length;i++){
                str += `
                <a class="reAttention" >
                        <div class="reHeard" onclick=headToDetail(this) data-id='${ans[i].id}' style="background-image:url(${ans[i].portrait})"></div>
                        <div class="nameAbstract" onclick=headToDetail(this) data-id='${ans[i].id}'>
                            <div class="reName">${ans[i].name}</div>
                            <div class="reAbstract" title="${ans[i].resume}">${ans[i].resume}</div>
                        </div>
                        <div class="focusBtn" data-id='${ans[i].id}' onclick=followthis(this)>关注</div>
                </a>
                `
            }
            $('.reContent')[0].innerHTML = str
        }).catch(err=>{
            console.log(err)
        })
    }else{
        axios({
            method:"get",
            url:'/index/recommendS'
        }).then(data=>{
            let ans = data.data.data.data
            let str = ''
            $('.reContent')[0].innerHTML = ''
            for(let i = 0;i < ans.length;i++){
                str += `
                <a class="reAttention" >
                        <div class="reHeard" onclick=headToDetail(this) data-id='${ans[i].id}' style="background-image:url(${ans[i].portrait})"></div>
                        <div class="nameAbstract" onclick=headToDetail(this) data-id='${ans[i].id}'>
                            <div class="reName">${ans[i].name}</div>
                            <div class="reAbstract" title="${ans[i].resume}">${ans[i].resume}</div>
                        </div>
                        <div class="focusBtn" data-id='${ans[i].id}' onclick=followthis(this)>关注</div>
                </a>
                `
            }
            $('.reContent')[0].innerHTML = str
        }).catch(err=>{
            console.log(err)
        })
    }
})
}
function hotSearch(){
    axios.get('/index/hotSearch')
    .then(data=>{
        let ans = data.data.data.data
        if(typeof ans == 'string'){
            $('.hotContainer')[0].innerHTML = `${ans}`
        }else{
            let str = ''
            for(a in ans){
                str += `
                <a class="hot" onclick=getClassfy(this)>${ans[a]}</a>
                `
            }
            $('.hotContainer')[0].innerHTML = str

        }
    })
    .catch(err=>{
        console.log(err)
    })
}
//页面加载之后要运行函数放进去推荐关注和热门搜索
getRecommend()
hotSearch()

//点推荐关注上的关注
function followthis(a){
    userMessageS().then(data=>{
        let sessionUserid=undefined
        if(data.data.session){
            sessionUserid=data.data.session.id
        }
    
    if(sessionUserid==undefined){
        // location.href='/login'
        toLoginTipFunc()
    }else{
        if(a.innerHTML == '已关注'){
            a.innerHTML = '关注'
            a.style.backgroundColor = '#fda1a9'
            a.style.color = 'white'
        }else{
            a.innerHTML = '已关注'
            a.style.backgroundColor = '#FAEDED'
            a.style.color = '#D6222E'
        }
        let followeeId = a.getAttribute('data-id')
        axios({
            method:'post',
            url:`/index/folloUser`,
            data:{
                followeeId:Number(followeeId),
                userId:Number(sessionUserid)
            }
        }).then(data=>{
            let ans = data.data.data.data
            console.log(ans)
            //ans为1==关注上了，0==取消关注了
        }).catch(err=>{
            console.log(err)
        })
    }
})
}

//点击推荐关注的头像要去他的主页
function headToDetail(a){
    let id = a.getAttribute('data-id')
    window.location.href = `/picture/picture?headId=${id}`
}



//点热门搜索要去到搜索页面
function getClassfy(a){
    window.location.href = `/picture/search?kw=${a.innerHTML}`
}

//点击推荐关注上面的换一批
$('.refresh')[0].onclick = getRecommend
